<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>电子病历浏览</title>

<script type="text/javascript" src='<%=request.getContextPath()%>/script/jquery/plug/viewer/jquery.js'></script> 
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/viewer/jqueryui.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/media/jquery.media.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery/plug/media/jquery.metadata.js" ></script>

</head>
<body>
<div class="easyui-panel"  data-options="fit:true,border:0" >
		<div id="" class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;">
			<!-- 左边树菜单 -->
			<div id='' data-options="region:'west',split:true" style="width:20%;height:100%;border-left:0;">
				<p style="text-align:center;">
					<label id="fname" class="shootFontBold"></label>&nbsp;
					<label>(病案号: </label><label id="fprn" class="shootFontBold"></label><span>)</span>
					<span id="currentIndex" style="display:none;"></span><!-- 保存当前选中的树节点元素下标值 -->
				</p>
				<ul id="EMR_file_browse_tree" ></ul>
			</div>
			<!-- 浏览区域 -->
			<div id="shoot_center" data-options="region:'east',split:true" style="width:80%;height:100%">
				<!-- <div class="slide_container" > -->
				 <iframe src="" frameborder="0" id="emr_pdf_container" name="pdfContainer" frameborder="0" scrolling="no" style="width:99%; height:99%;"></iframe>
					<!--  <div class="pdf"></div> -->
			    <!-- </div> -->
			 </div>
		   <!-- 底部工具栏 start-->
		   <div data-options="region:'south'" style="width:100%;height:75px;" class="Cancel_borderLB">
			    <div class="paddingTBL" style="text-align: center;">  
		             <span id="emr_archiving_button"  class="spanbtn sbtnWidth" onclick ="archivingOperation()">
		              	<img src="<%=request.getContextPath()%>/image/icons/upload.png"><br/>归档
		             </span> 
			      </div>
			</div>
			<!-- 底部工具栏 end-->
			
			<span id="emr_file_dialog_title"  style="text-align: center;display: none;">
				 <label>病案号: </label><label id="EMR_file_browse_fprn" class="shootFontBold"></label>
				 <label>住院次数: </label><label id="EMR_file_browse_ftimes" class="shootFontBold"></label>&nbsp;&nbsp;
				 <label>住院ID: </label><label id="EMR_file_browse_fzyid" class="shootFontBold"></label>&nbsp;&nbsp;
				 <label>姓名: </label><label id="EMR_file_browse_fname" class="shootFontBold"></label>&nbsp;&nbsp;
				 <label>出院日期: </label><label id="EMR_file_browse_fcydate" class="shootFontBold"></label>&nbsp;&nbsp;
				 <label>条码号: </label><label id="EMR_file_browse_fbarcode" class="shootFontBold"></label>
		    </span> 
	   </div>
</div>

<script type="text/javascript">
//标识符;用于标识不同页面调用此页面，并开放对应的权限操作。
//1:归档页面调用
//2:浏览图片时调用
var tag = '<%=request.getParameter("tag")%>'; 
var dialog = '<%=request.getParameter("dialog")%>';  //传入当前dialog ID
switch(tag){
	case "1":
		$("#emr_archiving_button").css("display","");
		break;
	case "2":
		$("#emr_archiving_button").css("display","none");
		$(".spansplit:eq(1) ").css("display","none");
		break;
}
$("#EMR_file_browse_fprn").html('<%=request.getParameter("fprn")%>');
$("#fprn").html('<%=request.getParameter("fprn")%>');
$("#EMR_file_browse_fzyid").html('<%=request.getParameter("fzyid")%>');
$("#EMR_file_browse_ftimes").html('<%=request.getParameter("ftimes")%>');
$("#EMR_file_browse_fname").html(decodeURI('<%=request.getParameter("fname")%>'));
$("#fname").html(decodeURI('<%=request.getParameter("fname")%>'));
$("#EMR_file_browse_fcydate").html('<%=request.getParameter("fcydate")%>');
$("#EMR_file_browse_fbarcode").html('<%=request.getParameter("fbarcode")%>');

$('#index_prompt').html("正在加载归档文件，请稍等...").dialog('open');
$("#EMR_file_browse_tree").tree({
	url : ctx + "/MedicalShootManage/EMRTypeTree",
	animate : true,
	checkbox : false,
	queryParams : {
		"fzyid" : $("#EMR_file_browse_fzyid").text(),
		"fprn" : $("#EMR_file_browse_fprn").text(),
		"ftimes" : $("#EMR_file_browse_ftimes").text(),
		"fname" : $("#EMR_file_browse_fname").text()
	},
	onSelect:function(node){
		if(node.text != "病案封面"){
	    	//点击分为两种情况：情景一，直接点击图片;情景二：点击二级菜单;
	   		if(!node.children){//情景一
	   			var src = '<%=request.getContextPath()%>/'+node.attributes;
	   			var isMore = false; //为false，则表示单张图片
	   			var Parent = $("#EMR_file_browse_tree").tree("getParent",node.target);
	   			$("#emr_pdf_container").attr("src",ctx+"/viewer?file="+src);
	   			//$("#currentModel").html(Parent.text);
	   			/* $('.pdf').media({ 
				   	width:     $("#shoot_center").innerWidth()-10, 
				    height:    $("#shoot_center").innerHeight()-10, 
				    autoplay:  true, 
				    src:       src, 
				    params: 	{toolbar:false},
				    caption:   false
				}); */
	   			/* $.ajax({
	   				url: ctx + "/MedicalShootManage/encodeIMG",
	   				dataType : 'json',
	   				type : 'post',
	   				data:{
	   					"path" : src,
	   					"isMore" : isMore
	   				},
	   				success:function(){
	   					EMRFileBrowseFun.putImg(node);
	   				},
	   				error:function(){
	   					$.messager.alert("提示","解密图片失败,请联系管理员！","info");
	   				}
	   			}); */
	   		}else{ //情景二
	   			//如果当前二级菜单没有任何图片，则不执行以下方法
	   			if(node.children.length > 0){ 
	   				EMRFileBrowseFun.putImg2(node);
	   			}else{
	   				return;
	   			}
	   		}
		}
	},
	onLoadSuccess:function(){
		$('#index_prompt').dialog('close');
	}
});

// function 
 var EMRFileBrowseFun = {
	 //直接点击图片执行的方法
	 putImg : function(node){
		 var id = node.id; 	//id绑定了图片编号
			var Src = node.attributes;
			var imgNumber = id.substring(id.lastIndexOf(",")+1,id.length);	//拆分图片编号
			
			$("#browsePageSlider").siblings("a").remove(); //先清空插件的元素
			if(Src.substring(Src.lastIndexOf(".")+1,Src.length) == "jpg"){
				var imgName = "";
				var parent = $("#EMR_file_browse_tree").tree("getParent",node.target);
				var pageNumber = node.text;
				var path = node.attributes;
				var parentText = parent.text;//父类标题
				var cateNumber = parent.attributes;//图片分类编码
				var src2 = Src.replace(/\\/g,'/');
				var index = src2.lastIndexOf("/");
				var imgSrc = src2.substring(index+1,Src.length);
				
				var srcPath=ctx + "/upload/"+sysFcode+"/"+imgSrc; 
				$("#browsePageSlider").html( 
						 "<div class='wrapper'>"
					         +"<div id='browsePageViewer' class='viewer iviewer_cursor' style='overflow: scroll;'></div><br/>"
					    +"</div>"
				     
					 	+ "<div class='caption'>" +
							"<span class='PageNumber'>"+pageNumber+"&nbsp;"+parentText+"&nbsp;"+imgSrc+"</span>" +
							"<span class='auditImgNumber' style='display:none;'>"+imgNumber+"</span>" +
							"<span class='imgCategory' style='display:none;'>"+cateNumber+"</span>" +
							"<span class='imgPath' style='display:none;'>" + path + "</span>" +
							"<span class='pageCode' style='display:none;'>" + pageNumber + "</span>" +
						"</div>" );  
				 
					    $("#browsePageSlider").removeClass("slide");
					    EMRFileBrowseFun.slider_RsViewer("browsePageViewer",srcPath);
						
					 	if(!node.children){ 
							$(".slide_nav").css("display",'none')
						}    
			}else{
				return ;
			}
	 },
	//放置图片至浏览区域
	 putImg2 : function(node){
		 var imgName = "";
			var html = "";
			var id = node.id; 	//id绑定了图片编号
			var imgNumber = id.substring(id.lastIndexOf(",")+1,id.length);	//拆分图片编号
			var parent = $("#EMR_file_browse_tree").tree("getNode",node.target);
			var parentText = parent.text;//父类标题
			$("#currentModel").html(parent.text);
			var cateNumber = parent.attributes;//图片分类编码
			var parentChildren = parent.children;//父类的子节点数组
			var path = "";
			var isMore = true; //为true，则解密多张图片
			for (var j = 0; j < parentChildren.length; j++) {
				var originPath = parentChildren[j].attributes; //图片路径
				if(j >0){
					path += ","+originPath;
				}else{
					path += originPath;
				}
			}
			$.ajax({
				url: ctx + "/MedicalShootManage/encodeIMG",
				dataType : "json",
				type : "post",
				data : {
					"path" :path,
					"isMore" : isMore
				},
				success:function(){
					$("#browsePageSlider").siblings("a").remove(); //先清空插件的元素
					//循环获取子节点
					for (var i = 0; i < parentChildren.length; i++) {
						var src = parentChildren[i].attributes; //图片路径
						var pageNumber = parentChildren[i].text;//图片页码
						var id = parentChildren[i].id; //图片编号
						//拆分图片编号
						var imgNumber = id.substring(id.lastIndexOf(",")+1,id.length);
						//截取图片路径
						var src2 = src.replace(/\\/g,'/');
						var index = src2.lastIndexOf("/");
						var imgSrc = src2.substring(index+1,src.length);
					   
						html += "<li>"  
							 //+"<div class='wrapper'>"
					         +"<div id='browseViewer"+i+"'"+" class='viewer iviewer_cursor' style='height:98%;overflow:scroll;border:0px solid #000000;'></div><br/>"
					         //+"</div>" 
							+"<div class='caption'>" +
								"<span class='PageNumber'>" + pageNumber + "&nbsp;" + parentText + "&nbsp;" + imgSrc + "</span>" +
								"<span class='auditImgNumber' style='display:none;'>" + imgNumber + "</span>" +
								"<span class='imgCategory' style='display:none;'>" + cateNumber + "</span>" +
								"<span class='imgPath' style='display:none;'>" + src + "</span>" +
								"<span class='pageCode' style='display:none;'>" + pageNumber + "</span>" +
							"</div>" +
							"</li>";    
					}
					
					$("#browsePageSlider").html(html); 
					EMRFileBrowseFun.slider(); //渲染特效
					
					for (var i = 0; i < parentChildren.length; i++) { 
						var src = parentChildren[i].attributes; //图片路径 
						//截取图片路径
						var src2 = src.replace(/\\/g,'/');
						var index = src2.lastIndexOf("/");
						var imgSrc = src2.substring(index+1,src.length);
						
						var srcPath=ctx + "/upload/"+sysFcode+"/"+imgSrc;
						EMRFileBrowseFun.slider_RsViewer("browseViewer"+i,srcPath); 
					} 
				}, 
				error:function(){
				//	$.messager.alert("提示","解密图片失败,请联系管理员！","info");
				}
			});
	 },
	//图片播放效果
	slider : function(){
		$("#browsePageSlider").responsiveSlides({
		    auto: false,
		    pager: false,
		    nav: true,
		    speed: 500,
		    // 对应外层div的class : slide_container
		    namespace: "slide"
	    });
	},
	//鼠标滚动_图片放大
	slider_RsViewer : function(iviewerId,srcPath){
		 /* 带有图片旋转功能的时候才用此*/
		  var $PA = jQuery; 
		  var viewer;
	      viewer = $PA("#"+iviewerId).iviewer({
	  	  src:srcPath
	    });
	},
	//关闭浏览页
	close : function(){
		$("#"+dialog).dialog('close');
	}
 };


 // 键盘事件  
$(document).keydown(function(event){
	e = event ? event : (window.event ? window.event : null);
	switch(e.keyCode){
		case 27: //退出
			EMRFileBrowseFun.close();
			break;
	}
 });
 
//归档操作
function archivingOperation(){
	$.messager.confirm("提示","确定进行归档操作？",function(r){
		if(r){
			$('#index_prompt').html("正在归档，请稍等...").dialog('open');
			$.ajax({
				url :ctx + '/Archiving/archivingOperation',
				dataType : 'json',
				type : "post",
				data : {
					'fzyid' : $("#EMR_file_browse_fzyid").text(),
					'fprn' : $("#EMR_file_browse_fprn").text(),
					'ftimes' : $("#EMR_file_browse_ftimes").text(),
					'fname' : $("#EMR_file_browse_fname").text()
				},
				success:function(data){
					$('#index_prompt').dialog('close');
					if(data){
						$.messager.alert('提示','归档成功！','info',function(){
							//关闭当前面板
							var tab = $('#tabs').tabs('getSelected');
							var index = $('#tabs').tabs('getTabIndex',tab);
							$('#tabs').tabs('close',index);
							
							$('#tabs').tabs('select','病案集中归档');
							queryArchiving();
						});
					}else{
						$.messager.alert('提示',data,'info');
					}
				},
				error:function(){
					$.messager.alert('提示','归档失败，请联系管理员！','info');
				}
			});
		}
	});
}

</script>
</body>
</html>